package com.wuseguang.springcloud.controller;


import com.wuseguang.springcloud.Filter.RequestParameterWrapper;
import com.wuseguang.springcloud.entity.Prize;
import com.wuseguang.springcloud.service.PrizeService;
import com.wuseguang.springcloud.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 奖品表 前端控制器
 * </p>
 *
 * @author
 * @since 2020-06-19
 */
@RestController
@RequestMapping("/jurisdiction")
public class PrizeController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private PrizeService prizeServiceImpl;


    /**
     * 教师添加奖品
     *
     * @param prize 奖品
     * @return
     */
    @RequestMapping("/addPrize")
    public Result addPrize(RequestParameterWrapper request, Prize prize) {
        logger.info("教师添加奖品");
        //获取学校id
        String schoolId = request.getParam("schoolId");
        //教师id
        String teacherId = request.getParam("teacherId");
        prize.setTeacherId(Integer.valueOf(teacherId));
        prize.setSchoolId(Integer.valueOf(schoolId));

        return prizeServiceImpl.addPrize(prize);
    }

    /**
     * 查询教师发布的活动
     * @param request
     * @param indexNo
     * @param rows
     * @return
     */
    @RequestMapping("/findTeacherPrize")
    public Result findTeacherPrize(RequestParameterWrapper request,
                                   @RequestParam(value = "indexNo", required = false, defaultValue = "1") Integer indexNo,
                                   @RequestParam(value = "rows", required = false, defaultValue = "20") Integer rows) {
        logger.info("查询教师发布的活动");
        //获取教师id
        String teacherId = request.getParam("teacherId");

        return prizeServiceImpl.findTeacherPrize(teacherId, indexNo, rows);
    }

    /**
     * 查询教师发布的活动兑换信息
     * @param request
     * @return
     */
    @RequestMapping("/findTeacherPrizeRecord")
    public Result findTeacherPrizeRecord(RequestParameterWrapper request,
                                         @RequestParam(value = "indexNo", required = false, defaultValue = "1") Integer indexNo,
                                         @RequestParam(value = "rows", required = false, defaultValue = "20") Integer rows){
        logger.info("查询教师发布的活动兑换信息");
        //获取教师id
        String teacherId = request.getParam("teacherId");
        return prizeServiceImpl.findTeacherPrizeRecord(teacherId, indexNo, rows);
    }

    /**
     * 撤销或确认活动记录
     * @param request
     * @param recordId 兑换记录id
     * @param state 0学生已兑换,1已撤销,2教师已确定
     * @return
     */
    @RequestMapping("/updatePrizeRecordState")
    public Result updatePrizeRecordState(RequestParameterWrapper request,
                                         @RequestParam(value = "recordId") Integer recordId,
                                         @RequestParam(value = "state") Integer state){
        logger.info("撤销或确认");
        return prizeServiceImpl.updatePrizeRecordState(recordId,state);
    }

    /**
     * 下架奖品
     * @param request
     * @param id
     * @return
     */
    @RequestMapping("/dismountPrize")
    public Result dismountPrize(RequestParameterWrapper request,
                                @RequestParam(value = "id") Integer id){
        logger.info("下架奖品");
        return prizeServiceImpl.dismountPrize(id);
    }

    /**
     * 奖品兑换记录查看
     * @param request
     * @param
     * @return
     */
    @RequestMapping("/queryIntegral")
    public Result queryIntegral(RequestParameterWrapper request){
        String teacherId = request.getParam("teacherId");
        logger.info("查询剩余积分");
        return prizeServiceImpl.queryIntegral(teacherId);
    }

    /**
     * 奖品兑换记录查看
     * @param request
     * @param recordId 记录id
     * @return
     */
    @RequestMapping("/viewRecords")
    public Result viewRecords(RequestParameterWrapper request,
                              @RequestParam(value = "recordId") Integer [] recordId){
        logger.info("奖品兑换记录查看");
        return prizeServiceImpl.viewRecords(recordId);
    }

}


